package com.txy.filter;


import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.extension.Activate;
import com.alibaba.dubbo.rpc.*;
import com.txy.Monitor;

@Activate(group = Constants.CONSUMER)
public class TPMonitorFilter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        String methodName = RpcContext.getContext().getMethodName();
        long startTime = System.currentTimeMillis();
        Result result = invoker.invoke(invocation);
        long endTime = System.currentTimeMillis();
//        System.out.println(methodName +"耗时:"+(endTime-startTime)+"ms");

        Monitor.getInstance().put(methodName, endTime-startTime);
        return result;
    }

}
